fix: fill first empty waypoint slot instead of counting filled waypoints#480
Open
wursterje wants to merge 2 commits into
Open
fix: fill first empty waypoint slot instead of counting filled waypoints#480wursterje wants to merge 2 commits into
wursterje wants to merge 2 commits into
Conversation
Contributor
|
Thanks so much for the contribution. Will start the review sometime this week. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes map-click waypoint placement when the route is opened with an empty start and a pre-filled destination (e.g. ?loc=&loc=<dest>), by selecting the first empty waypoint slot instead of deriving the target slot from the count of filled waypoints.
Changes:
- Store
lrmControl.getWaypoints()in a localwaypointsvariable for reuse. - Replace the “count-filled-waypoints → compute index” logic with “find first empty slot → fill it”.
- Keep existing behavior when all slots are filled by replacing the last waypoint.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
716
to
717
| return; | ||
| } |
Comment on lines
+734
to
+735
| // All slots are filled: replace the last one. | ||
| lrmControl.spliceWaypoints(waypoints.length - 1, 1, waypoint); |
Contributor
|
@wursterje Please have a look at the comments from the review bot, especially the second comment on using |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the page is opened with only the destination pre-filled via URL (
?loc=&loc=<dest>), clicking the map overwrites the destination instead of filling the empty start slot.The waypoint array looks like this:
addWaypoint()counted the number of filled waypoints (= 1) and derived the target slot from that count. Since it assumed filled waypoints are always packed at the front, it computed slot 1 and overwrote the destination.Fix
Instead of counting filled waypoints, scan the array for the first slot without a coordinate and fill that. If all slots are filled, fall back to replacing the last one (previous behaviour).
Use case
Sites that link to the router with a pre-filled destination (
?loc=&loc=<institution>) so visitors can set their own start pointwith a single map click. The old behaviour destroyed the destination on that click.
Fixes #479